package com.leo.ui;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.scene.SubScene;
import com.leo.TankApp;
import com.leo.common.Config;
import javafx.animation.PauseTransition;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.util.Duration;

public class SuccessedScene extends SubScene {

    private final PauseTransition pt;

    public SuccessedScene() {
        Text text = new Text("Score 200");
        text.setFill(Color.WHITE);
        text.setFont(Font.font(35));
        StackPane stackPane = new StackPane(text);
        stackPane.setStyle("-fx-background-color: gray");
        stackPane.setPrefSize(FXGL.getAppWidth(), FXGL.getAppHeight());
        getContentRoot().getChildren().add(stackPane);

        // 暂停动画
        pt = new PauseTransition(Duration.seconds(2));
        pt.setOnFinished(event -> {
            if (FXGL.geti("level") < Config.MAX_LEVEL) {
                FXGL.getSceneService().popSubScene();
                FXGL.inc("level", 1);
                FXGL.<TankApp>getAppCast().startLevel();
            } else {
                FXGL.getNotificationService().pushNotification("胜利！！！");
                FXGL.getGameController().gotoMainMenu();
            }
        });
    }

    @Override
    public void onCreate() {
        pt.play();
    }
}
